Skip to content

Add shared server test helpers, condense recent tests, and speed up slow BVT tests - #8367

Merged
labkey-jeckels merged 15 commits into
developfrom
fb_test_helpers
Nov 25, 2026
Merged

labkey-jeckels merged 15 commits into
developfrom
fb_test_helpers

Conversation

@labkey-jeckels

@labkey-jeckels labkey-jeckels commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Rationale

Make server-side integration tests easier to write and faster to run. Many recently added tests hand-roll the same container, user, sample type, and update-service setup, hard-coded names that already had constants, and repeated near-identical test methods. Separately, the slowest server-side test classes in BVT-B spend most of their time in fixed sleeps, timeouts, and repeated container and study setup rather than in the code they verify.

Related Pull Requests

Changes

  • Add shared test helpers for running work on a separate request thread, writing rows through a query update service, creating sample types, and skipping tests by database or assertion mode
  • Extend the container-scoping test base with throwaway projects, restricted folders, and role grants to groups
  • Move recently added tests onto the shared helpers and production constants
  • Fold near-duplicate test methods into table-driven tests that assert the same cases
  • Share containers across a class's tests where each test only checks its own data
  • Shorten fixed sleeps and waits in the slowest BVT tests, with test-only overrides for the stuck async worker timeout and the request timeout sweep interval
  • Flush detailed audit events on the shared row batch size, so its test can cross batch boundaries with a few rows
  • Wait for the file watcher events the test asserts rather than OS-specific event counts

Tasks

  • Claude Code Review
  • Manual Testing - N/A
  • Test Automation

Moves recently added tests onto new shared helpers (JunitUtil, RequestTestUtil, QueryUpdateServiceTestUtil, SampleTypeTestHelper, AbstractContainerScopingTest) and folds near-duplicate tests into table-driven ones with the same coverage.
# Conflicts:
#	announcements/src/org/labkey/announcements/AnnouncementsController.java
#	experiment/src/org/labkey/experiment/api/SampleTypeServiceImpl.java
@labkey-jeckels labkey-jeckels changed the title Add shared server test helpers and condense recent tests Add shared server test helpers, condense recent tests, and speed up slow BVT tests Nov 20, 2026
@labkey-jeckels

Copy link
Copy Markdown
Contributor Author

Runtime of the server-side test classes this PR speeds up, in BVT-B postgres. Before is the median of 11 BVT-B runs from Nov 19 (develop and feature branches); after is this branch's run https://teamcity.labkey.org/buildConfiguration/LabkeyTrunk_BvtBPostgres/4274194

Test class Before After Change
SampleProvidedAmountAuditTestCase 35.8 s 1.3 s −34.4 s
AsyncQueryRequest$TestCase 23.6 s 5.2 s −18.3 s
FileSystemWatcherImpl$TestCase 16.0 s 2.3 s −13.7 s
TransactionFilter$TestCase 21.6 s 9.9 s −11.7 s
PipelineQueueImpl$TestCase 8.0 s 0.8 s −7.2 s
ColumnFactsCache$TestCase 8.5 s 4.5 s −4.0 s
BlockingCache$BlockingCacheTest 7.0 s 3.4 s −3.6 s
DatasetLsidImportHelper$TestCase 8.8 s 5.4 s −3.4 s
TreatmentManager$TreatmentDataTestCase (customModules) 10.0 s 7.3 s −2.7 s
ExperimentStressTest 40.1 s 40.7 s +0.6 s
Total 179.4 s 80.9 s −98.5 s

ExperimentStressTest didn't improve: its random pre-insert delay turned out not to be the bottleneck, so its time is dominated by the inserts themselves. The after column is a single run, and several unrelated classes ran slower on that agent, so the drop in overall JUnit time was smaller than the total above.

@labkey-jeckels
labkey-jeckels marked this pull request as ready for review November 23, 2026 01:45
Comment on lines +215 to +219
/** Skips the test unless the labkey scope is PostgreSQL */
public static void assumePostgres()
{
Assume.assumeTrue("Requires PostgreSQL", DbScope.getLabKeyScope().getSqlDialect().isPostgreSQL());
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we even need this anymore? Do we expect to add a new primary database type (or re-add SQL Server? 😱 )

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, not needed. Removed.

@labkey-jeckels
labkey-jeckels requested review from a team and labkey-tchad November 24, 2026 02:11
*/
protected Container createProject(String name, Module... enabledModules)
{
String projectName = getClass().getName().replaceAll("[^A-Za-z0-9]", "_") + "-" + name;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider prefixing project names with _junit- to make it clear where these projects came from, in case the cleanup fails for some reason.

Suggested change
String projectName = getClass().getName().replaceAll("[^A-Za-z0-9]", "_") + "-" + name;
String projectName = "_junit-" + getClass().getName().replaceAll("[^A-Za-z0-9]", "_") + "-" + name;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. I ended up merging the PRs and doing this as a followup. #8390

@labkey-nicka
labkey-nicka removed the request for review from a team November 25, 2026 23:13
labkey-jeckels added a commit to LabKey/testAutomation that referenced this pull request Nov 25, 2026
)

## Rationale
Give module tests a shared home for request cancellation checks and the
samples query schema name, which two test classes had copied and several
redeclared.

## Related Pull Requests
- LabKey/platform#8367
- LabKey/limsModules#2618
- LabKey/labkey-workspaces#81
- LabKey/customModules#296

## Changes
- Add a helper for waiting on the notification WebSocket and reading
request cancel metrics
- Add a constant for the samples query schema name
@labkey-jeckels
labkey-jeckels merged commit 32c7fa7 into develop Nov 25, 2026
11 checks passed
@labkey-jeckels
labkey-jeckels deleted the fb_test_helpers branch November 25, 2026 23:48
labkey-jeckels added a commit to LabKey/customModules that referenced this pull request Nov 25, 2026
#296)

## Rationale
Speed up a slow BVT server-side test: the two TreatmentManager container
scoping tests each created and deleted their own pair of study
containers.

## Related Pull Requests
- LabKey/platform#8367
- LabKey/limsModules#2618
- LabKey/testAutomation#3313
- LabKey/labkey-workspaces#81

## Changes
- Create the study containers once per test class and share them between
the two container scoping tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants